<template>
  <div class="deliveryEdit">
    <div class="dropdown">
      <el-button size="mini" @click="queryTSalOrderNtry">刷新</el-button>
      <el-button size="mini" type="primary" @click="toExamineFun">排单确认</el-button>
    </div>
    <el-tabs v-model="activeName" class="tabs" @tab-click="handleClick">
      <el-tab-pane :label="$t('market.info')" name="first">
        <el-form ref="purchaseRef" :model="prodValue" label-width="100px" size="mini" disabled>
          <el-form-item :label="$t('market.state')" prop="fdocumentStatus">
            <el-tag :type="prodValue.stateColor">{{ prodValue.fdocumentStatus }}</el-tag>
          </el-form-item>
          <el-form-item :label="$t('market.billType')">
            <el-input
              v-model.trim="prodValue.fbillTypeName"
              disabled
            />
          </el-form-item>
          <el-form-item :label="$t('market.billNo')">
            <el-input v-model="prodValue.fbillNo" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.fdate')" prop="fdate">
            <el-input
              v-model="prodValue.fdate"
            />
          </el-form-item>
          <el-form-item :label="$t('market.cust')" prop="fcustomerId">
            <el-input v-model.trim="prodValue.fcustName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.headDelivery')" prop="fheadDeliveryWay">
            <el-input v-model.trim="prodValue.fheadDeliveryWayName" size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.recCondition')" prop="fstockerid">
            <el-input v-model.trim="prodValue.freccondiTionName" />
          </el-form-item>
          <el-form-item :label="$t('market.saler')" prop="fsaleSmanId">
            <el-input v-model.trim="prodValue.fsalerName" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.paezCom')" prop="fpaeztext1">
            <el-select v-model="prodValue.F_PAEZ_COMBO" size="mini" disabled>
              <el-option
                v-for="item in standard"
                :key="item.fid"
                :label="item.fname"
                :value="item.fid"
              />
            </el-select>
          </el-form-item>
          <el-form-item :label="$t('market.paezText')">
            <el-input v-model.trim="prodValue.F_PAEZ_TEXT" />
          </el-form-item>
          <el-form-item :label="$t('market.paezText1')">
            <el-input v-model.trim="prodValue.F_PAEZ_TEXT1" size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.paezText2')">
            <el-input v-model.trim="prodValue.F_PAEZ_TEXT2" size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.gold')">
            <el-input v-model.trim="prodValue.fgold" size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.note')" style="width: 500px">
            <el-input v-model.trim="prodValue.fnote" size="mini" style="width: 100%" />
          </el-form-item>
        </el-form>
        <!--明细表格-->
        <div>
          <jc-table
            :table-data="saleDetails"
            :table-header="tableHeader"
            :table-height="tableHeight"
            :get-summaries="getSummaries"
            show-summary
            table-selection
            @selectionChange="selectionDatas"
          >
            <template v-slot:btnState="col">
              <el-checkbox
                v-model="col.scope.row.fisFree"
                :value="col.scope.row.fisFree"
                disabled
              />
            </template>
            <!--    是否排单    -->
            <template v-slot:text2Slot="clo">
              <el-tag v-if="clo.scope.row.fscheduling === 1" type="success">{{ $t('market.yes') }}</el-tag>
              <el-tag v-else-if="clo.scope.row.fscheduling === 0" type="warning">
                {{ $t('market.no') }}
              </el-tag>
            </template>
          </jc-table>
        </div>
      </el-tab-pane>
      <el-tab-pane :label="$t('market.fince')" name="two">
        <el-form ref="purchaseRef" :model="prodValue" label-width="100px" disabled>
          <el-form-item :label="$t('market.settleCurr')" prop="fsettlecurrId">
            <el-input v-model.trim="prodValue.fsettleCurrName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.exchangeType')" prop="fsettleTypeId">
            <el-input v-model.trim="prodValue.fexchangeTypeName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.localCurr')" prop="freceiptconditionid">
            <el-input v-model.trim="prodValue.flocalCurrName" size="mini" disabled />
          </el-form-item>
          <el-form-item :label="$t('market.exchangeRate')">
            <el-input v-model="prodValue.fexchangeRate" disabled size="mini" />
          </el-form-item>
          <el-form-item :label="$t('market.priceList')">
            <el-input v-model="prodValue.fpriceListName" size="mini" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:taxamount')" :label="$t('market.billtaxamount')">
            <el-input v-model="prodValue.fbilltaxamount" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biamount')" :label="$t('market.billamount')">
            <el-input v-model="prodValue.fbillamount" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biallamount')" :label="$t('market.billallamount')">
            <el-input v-model="prodValue.fbillallamount" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:taxamount_c')" :label="$t('market.billtaxamount_lc')">
            <el-input v-model="prodValue.fbilltaxamount_lc" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biamount_c')" :label="$t('market.billamount_lc')">
            <el-input v-model="prodValue.fbillamount_lc" disabled />
          </el-form-item>
          <el-form-item v-if="bomCost('sal:biallamount_c')" :label="$t('market.billallamount_lc')">
            <el-input v-model="prodValue.fbillallamount_lc" disabled />
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane :label="$t('market.other')" name="log">
        <jc-marker
          ref="log"
          :fnumber="prodValue.fbillNo"
          other-height="68vh"
          :other-url-object="otherUrlObject"
        />
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import jumpMateriel from '@/components/JumpMateriel'
import mixinsImg from '@/views/market/marketManage/createMarkerOrder/components/mixinsImg'
import { queryTSalOrderNtry, SchedulingConfirm } from '@/api/marketManage/marketOrder'
import { toMxAmina } from '@/components/ToMxamineState'
import operability from '@/mixin/Operability'
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'
import jcMarker from '@/components/marker'

export default {
  name: 'EditDelivery',
  components: {
    jcMarker
  },
  mixins: [jumpMateriel, mixinsImg, autocomplete, operability],
  data() {
    return {
      otherUrlObject: {},
      activeName: 'first', // 基本信息
      isDisabled: false,
      prodValue: {}, // 表单数据
      tableHeight: '65vh',
      standard: [],
      saleDetails: [],
      tableHeader: [
        { label: this.$t('market.scheduling'), type: 'text2', prop: 'fscheduling', width: '80' },
        { label: this.$t('market.frowType'), prop: 'frowTypeName', width: '80' },
        { label: this.$t('market.custmatNo'), prop: 'fcustmatNo' },
        { label: this.$t('market.custmatname'), prop: 'fcustmatname' },
        { label: this.$t('market.fmaterial'), prop: 'fnumber', width: '120px' },
        { label: this.$t('shop.fname2'), prop: 'fname', width: '120' },
        { label: this.$t('market.fmodel'), prop: 'fmodel', width: '100px' },
        { label: this.$t('shop.fspecificaTion'), prop: 'fspecificaTion', width: '120px' },
        { label: this.$t('market.fdescripTion'), prop: 'fdescripTion', minWidth: '200px' },
        { label: this.$t('market.funit'), prop: 'funitName', width: '80px' },
        { label: this.$t('market.fqty2'), prop: 'fqty', width: '80px' },
        { label: this.$t('market.fisFree'), type: 'state', prop: 'fisFree', width: '80px' },
        { label: this.$t('market.ftaxRate'), prop: 'ftaxrate', width: '80px' },
        { label: this.$t('market.fpaezAssistant'), prop: 'F_PAEZ_ASSISTANT_NAME', width: '120' },
        { label: this.$t('market.deliveryDate'), prop: 'fdeliveryDate', width: '160px' },
        { label: this.$t('market.paezText1'), prop: 'fpaeztext', width: '120px' },
        { label: this.$t('market.note'), prop: 'fnote', width: '150px' },
        { label: 'CBM', prop: 'cbm', width: '100px' }
      ],
      fentryData: [],
      fnumber: ''
    }
  },
  created() {
    this.queryTSalOrderNtry() // 获取订单列表数据
    this.queryFpaezCombo() // 品质标准
    this.tableHeight = window.innerWidth > 1440 ? 'calc(100vh - 260px)' : '63vh'
  },
  methods: {
    // 获取订单列表数据
    async queryTSalOrderNtry() {
      const fid = this.$route.params.id
      const DATA = { fid }
      const { data: RES } = await queryTSalOrderNtry(DATA)
      this.otherUrlObject = RES
      this.prodValue = toMxAmina(RES.header)
      this.saleDetails = RES.details
      this.isDisabled = this.prodValue.fdocumentStatus === this.$t('market.state1') || this.prodValue.fdocumentStatus === this.$t('market.state2') ||
        this.prodValue.fdocumentStatus === this.$t('market.state7')
      RES.details.map(res => {
        res.fisFree !== 0 ? res.fisFree = true : res.fisFree = false
        res.frowType = Number(res.frowType)
      })
    },
    // 公共函数
    toExamineFun() {
      const DATA = { EntryIds: this.fentryData }
      SchedulingConfirm(DATA).then(res => {
        if (res.code === 0) {
          this.detailsList()
          this.$message({ showClose: true, message: res.message, type: 'success' })
        } else {
          this.$confirm(res.message, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'error'
          })
        }
      })
    },
    // 明细列表 多选时触发的事件
    selectionDatas(val) {
      this.fentryData = []
      val.forEach(res => {
        this.fentryData.push(res.fentryId)
      })
    },
    // 点击tabs
    handleClick(tab) {
      if (tab.name === 'log') {
        this.$refs.log.otherlog()
      }
    }
  }
}
</script>
<style scoped lang="scss">
.deliveryEdit {
  @include listBom;
  .tabs{
    &::v-deep .el-tabs__content {
      min-height: calc(100vh - 200px);
    }
  }
  .tabPosit {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: 3.8vh;
    left: 0;
    background-color: rgba(255, 255, 255, 1);
    z-index: 99999!important;
  }
  .tabPosit1 {
    padding: 5px;
    box-shadow: 0 0 2px #aaa;
    position: absolute;
    top: -25.69vh;
    left:0;
    background-color: rgba(255, 255, 255, 1);
    z-index: 9999;
  }
  .el-input::v-deep .el-input__inner {
    height: 30px;
    line-height: 30px;
  }
  .el-tabs {
    &::v-deep.el-tabs__header {
      margin: 0 0 5px;
    }
    .el-form {
      display: flex;
      flex-wrap: wrap;

      .el-form-item {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        height: 36px;
        width: 275px;
        margin-bottom: 2px;
        .btnType{
          margin-right: 20px;
        }
        .el-date-editor.el-input{
          width: 100% !important;
        }
        .el-select{
          width: 100%;
        }
      }
    }
  }
}

.el-input__icon {
  cursor: pointer;
}

</style>
